package com.gdk.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.gdk.service.ArticleService;
import com.gdk.service.BannerService;
import com.gdk.service.GoodsService;
import com.gdk.service.LoginService;
import com.gdk.service.NavigationService;
import com.gdk.service.ServiceService;
import com.gdk.service.TreeService;
import com.gdk.utils.XVDateUtils;


/**
 * 客服controller
 * */

@Controller
public class ServiceController {
	
	
	@Autowired
    private ServiceService serviceService;
	

	/**
	 * 新增客服
	 * */
	@ResponseBody
	@RequestMapping("/addService.do")
	public int addService(@RequestParam Map<String,Object> map, HttpServletRequest request) {
		
		map.put("s_status", 1);
		
		int re_status = serviceService.addService(map);
		System.out.println("结果 : "+re_status);
		return re_status;
	}
	
	/**
	 * 查询所有客服
	 * */
	@RequestMapping("/selectAllService.do")
	public String selectAllTree(@RequestParam Map<String,Object> map, HttpServletRequest request) {
		
		System.out.println("查询  :  "+map);

		List<Map<String, Object>> allService = null;
		
		allService = serviceService.selectAllService();

		int itemCount = allService.size();
		
		request.setAttribute("allService",allService);
		return "jsp/service/service-list";
	}
	
	/**
	 *修改前查询客服详情
	 * */
	@RequestMapping("/preSelectServiceDetails.do")
	public String preSelectServiceDetails(@RequestParam Map<String,Object> map, HttpServletRequest request) {
		
		Map<String, Object> serviceDetails = serviceService.selectServiceDetails(map);
		
		
			/*if(treeDetails.get("ft_endtime") != null) {
				int p = Integer.valueOf(treeDetails.get("ft_endtime").toString());
				if(p != 0) {
					treeDetails.put("ft_endtime", XVDateUtils.MillisFormat(p));	
				}
			}
			*/
		request.setAttribute("serviceDetails",serviceDetails);
		return "jsp/service/service-edit";
	}
	
	/**
	 * 修改客服
	 * */
	@ResponseBody
	@RequestMapping("/updateService.do")
	public int updateService(@RequestParam Map<String,Object> map, HttpServletRequest request) {
		System.out.println("客服 : "+map);
		int shop = serviceService.updateServiceDetails(map);
		return shop;
	}


}